package com.mask.juc.v1.c_002;

import java.util.concurrent.TimeUnit;

/**
 * @author hx
 * @date 2021/10/11 10:36 上午
 */

public class T {
    public synchronized void m1(){
        System.out.println("线程名:"+Thread.currentThread().getName()+" m1 start...");
        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("线程名:"+Thread.currentThread().getName()+" m1 end");
    }

    public  void m2(){
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("线程名:"+Thread.currentThread().getName()+" m2");
    }

    public static void main(String[] args) throws Exception {
        T t = new T();

//        new Thread(() -> t.m1(), "t1").start();
//        new Thread(() -> t.m2(), "t2").start();

        new Thread(t::m1, "t1").start();
        new Thread(t::m2, "t2").start();
    }
}
